﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Bovril.PlayingCards.French;

namespace Bovril.Poker
{
    public class Hole : IComparable<Hole>
    {
        public Hole(Card card1, Card card2)
        {
            cards_ = new Card[2] { card1, card2 };
            Array.Sort(cards_, new CardComparer());
        }

        public HoleArchetype GetArchetype()
        {
            return new HoleArchetype(this);
        }

        public override string ToString()
        {
            return String.Format("{0}, {1}", Card1.ToString(), Card2.ToString());
        }

        public bool Contains(Card card)
        {
            for (int i = 0; i < 2; ++i)
            {
                if (cards_[i].Equals(card))
                    return true;
            }

            return false;
        }

        public int CompareTo(Hole other)
        {
            CardComparer cardComparer = new CardComparer();

            if (cardComparer.Compare(this.Card1, other.Card1) < 0)
                return -1;
            else if (cardComparer.Compare(this.Card1, other.Card1) > 0)
                return 1;

            if (cardComparer.Compare(this.Card2, other.Card2) < 0)
                return -1;
            else if (cardComparer.Compare(this.Card2, other.Card2) > 0)
                return 1;

            return 0;
        }

        public Card Card1 { get { return cards_[0]; } }
        public Card Card2 { get { return cards_[1]; } }

        private Card[] cards_;
    }
}
